﻿// Inner Fire 游戏引擎库
// ColliderInfo - 用于UI的Prefab
//
// Copyright (c) 2025 by 尔西大帝. All rights reserved.
//
// 用于UI的Prefab
//
// Author: 尔西大帝
// Email: 2670613871@qq.com
// Created: 2025-04-24

#include "collider_info.h"
#include <enum_parser.h>

namespace ifire::game {

ColliderInfo::ColliderInfo(ConfigManager* manager, const ikit::XmlNode& node)
    : ConfigInfo(manager, node("Name"))
    , type(ParseShapeType(node("Type")))
    , center(node("Center"))
    , box()
    , sphere()
    , capsule() {
  // 根据不同的类型，读取不同的参数
  if (type == ShapeType::Sphere) {
    sphere.radius = node("Sphere");
  } else if (type == ShapeType::Box) {
    box = node("Box");
  } else if (type == ShapeType::Capsule) {
    IVec3 capsule_node = node("Capsule");
    capsule.radius = capsule_node.x;
    capsule.start = capsule_node.y;
    capsule.end = capsule_node.z;
  }
}

ShapeType ParseShapeType(ikit::sstr name) {
  static std::pair<ikit::sstr, ShapeType> enums[] = {
      {"Particle", ShapeType::Particle}, //
      {"Sphere", ShapeType::Sphere},     //
      {"Box", ShapeType::Box},           //
      {"Capsule", ShapeType::Capsule}    //
  };
  static ikit::EnumParser<ShapeType> parser(enums, (int)ShapeType::Capsule + 1);
  return parser.Get(name, ShapeType::Sphere);
}

ikit::sstr GetShapeTypeName(ShapeType type) {
  static ikit::sstr enums[] = {
      "Particle", //
      "Sphere",   //
      "Box",      //
      "Capsule"   //
  };
  return enums[(int)type];
}

} // namespace ifire::game
